package org.delphy.indy2.containers
{
	import flash.display.DisplayObject;
	import flash.events.MouseEvent;
	import flash.events.Event;
	import flash.text.TextLineMetrics;
	
	import mx.containers.HBox;
	import mx.controls.Label;
	import mx.core.Application;
	import mx.managers.PopUpManager;
	import mx.styles.StyleManager;
	import mx.events.FlexMouseEvent;
	
	public class CarbonMagnifyWindow extends CarbonSlimPanel
	{
		
		public var text:String;
		
		private var notifyText:Label;
		
		private var layoutBox:HBox;
		
		public function CarbonMagnifyWindow()
		{
			super();
			
			resizable=false;
			horizontalScrollPolicy="off";
			verticalScrollPolicy="off";
			content.horizontalScrollPolicy="off";
			content.verticalScrollPolicy="off";
		}
		
		public function popUp():void{
			PopUpManager.addPopUp(this,DisplayObject(Application.application),true);
			PopUpManager.centerPopUp(this);
			
			addEventListener(MouseEvent.CLICK,onClick);
			addEventListener(FlexMouseEvent.MOUSE_DOWN_OUTSIDE,onClick);
		}
		
		private function onClick(evt:Event):void{
			PopUpManager.removePopUp(this);
		}
		
		override protected function createChildren():void{
			super.createChildren();
			
			layoutBox=new HBox();
			layoutBox.setStyle("horizontalAlign","center");
			layoutBox.setStyle("verticalAlign","middle");
			
			layoutBox.percentWidth=100;
			layoutBox.percentHeight=100;

			addChild(layoutBox);
			
			notifyText=new Label();
			notifyText.setStyle("color",StyleManager.getStyleDeclaration(".carbonMagnifyWindow").getStyle("color"));
			notifyText.setStyle("fontSize",StyleManager.getStyleDeclaration(".carbonMagnifyWindow").getStyle("fontSize"));
			notifyText.setStyle("fontWeight",StyleManager.getStyleDeclaration(".carbonMagnifyWindow").getStyle("fontWeight"));
			notifyText.setStyle("fontFamily",StyleManager.getStyleDeclaration(".carbonMagnifyWindow").getStyle("fontFamily"));

			layoutBox.addChild(notifyText);
			
		}
		
		override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void{
			super.updateDisplayList(unscaledWidth,unscaledHeight);
			
			notifyText.text=text;
			
			var metric:TextLineMetrics=notifyText.getLineMetrics(0);
			
			if(metric.width>=stage.stageWidth){
				width=stage.stageWidth-100;
			}
			else{
				width=metric.width+200;
			}
			
			if(metric.height>= stage.stageHeight){
				height=stage.stageHeight-30;
			}			
			else{
				height=metric.height+30;
			}		
		}
	}
}